package com.example.demo.Dao;

import org.springframework.core.io.Resource;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

public class CrawlData {

    private static RestTemplate restTemplate=new RestTemplate();
    private final static String uri ="https://gitee.com/dgut-sai/COVID-19/raw/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv";

    //爬取全球新冠肺炎病例数据
    public static InputStream getData() throws IOException {
        RequestEntity<Void> requestEntity= RequestEntity
                .get(URI.create(uri))
                .headers(httpHeaders -> httpHeaders.add("User-Agent","dgut"))
                .build();
        ResponseEntity<Resource> exchange = restTemplate.exchange(requestEntity, Resource.class);
        Resource body=exchange.getBody();
        InputStream inputStream = body.getInputStream();
        return inputStream;
    }

}
